package com.lz.football.module.chat
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.ChatEvent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 表情面板 
	 * @author Administrator
	 * 
	 */	
	public class FaceView extends Sprite
	{
		private static var _instance:FaceView;
		private var _skin:MovieClip;
		public function FaceView()
		{
			super();
			init();
		}
		private function init():void
		{
			_skin = Reflection.createInstance("com.football.chat.skin");
			this.addChild(_skin);
			addEventList();
		}

		private function addEventList():void
		{
			this.addEventListener(Event.ADDED_TO_STAGE,onAddStageHandler);
		}
		
		protected function onAddStageHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			this.stage.addEventListener(MouseEvent.MOUSE_UP,onstageClickHandler);
		}
		
		protected function onstageClickHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			this.stage.removeEventListener(MouseEvent.MOUSE_UP,onstageClickHandler);
			if(this.parent)this.parent.removeChild(this);
			
//			trace(event.target.name);
			var str:String = event.target.name;
			if(str.split("_")[0] == "f")
				AppEventDispatcher.getInstance().dispatchEvent(new ChatEvent(ChatEvent.CHAT_FACE,"/"+event.target.name));
		}
		
		public function showView():void
		{
			GlobalDef.GameContainer.addChild(this);
			
			this.x = this.stage.mouseX ;
			this.y = this.stage.mouseY - this.height;
		}
		public static function get instance():FaceView
		{
			if(_instance == null)_instance = new FaceView();
			return _instance;
		}

	}
}